<%@ include file="/WEB-INF/template/include.jsp"%>


<openmrs:htmlInclude file="/scripts/jquery/jquery-1.3.2.min.js" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/moduleResources/hospitalcore/scripts/jquery/jquery.PrintArea.js"></script>
<c:choose>
	<c:when test="${not empty model.listPatients}">
		<span class="boxHeader">List Patients</span>
		<table class="box">
			<tr>
				<th>Identifier</th>
				<th>Name</th>
				<th>Age</th>
			</tr>
			<c:forEach items="${model.listPatients }" var="patient"
				varStatus="varStatus">
				<tr class='${varStatus.index % 2 == 0 ? "oddRow" : "evenRow" } '>
					<td><a
						href="report.htm?orderDate=${param.orderDate}&identifier=${patient.patientIdentifier.identifier}">${patient.patientIdentifier.identifier}</a>
					</td>
					<td>${patient.givenName} ${patient.middleName}
						${patient.familyName}</td>
					<td>${patient.age}</td>
				</tr>
			</c:forEach>
		</table>
	</c:when>
	<c:otherwise>
		<c:choose>
			<c:when test="${not empty model.patient }">
				<div id="screenDisplay">
					<div align="center">
					<table cellspacing="5">
						<tr>
							<td width="75px" style="text-align:right;">ID. No:</td>
							<td width="200px"><b>${model.patient.patientIdentifier.identifier}</b></td>
							<td width="100px" style="text-align:right;">Age:</td>
							<td width="100px"><b>${model.patient.age}</b></td>
							<td width="75px" style="text-align:right;">Gender:</td>
							<td width="100px"><b><c:choose>
									<c:when test="${model.patient.gender eq 'M'}">Male</c:when>
									<c:otherwise>Female</c:otherwise>
								</c:choose>
								</b>
							</td>
						</tr>
						<tr>
							<td style="text-align:right;">Name:</td>
							<td><b>${model.patient.personName.givenName}
								${model.patient.personName.middleName}
								${model.patient.personName.familyName}
								</b>
							</td>
							<td style="text-align:right;">Order date:</td>
							<td><b>${param.orderDate}</b></td>
							<td></td>
							<td></td>
						</tr>
					</table>
					</div>
					<br />
					<table style="width: 90%" cellspacing="0">
						<tr>
							<td width="46%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; text-align:center;"><b>Test</b></td>
							<td width="27%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; text-align:center;"><b>Result</b></td>
							<td width="10%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; text-align:center;"><b>Unit</b></td>
							<td width="17%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; border-right: 1px solid; text-align:center;"><b>Reference Range</b></td>
						</tr>
						<c:forEach items="${model.nodes}" var="node">
							<c:if test="${not (node.level eq 1 and empty node.childNodes)}">
								<tr>
									<td style="border-left: 1px solid;">
										<div style="margin-left:${15*node.level}px;">
											<c:choose>
												<c:when test="${node.level eq 1}">
													<br />
													<strong>${node.name}</strong>
												</c:when>
												<c:otherwise>
												${node.name}
											</c:otherwise>
											</c:choose>
										</div>
									</td>
									<td style="border-left: 1px solid;"><div style="margin-left:10px;">${node.result}</div></td>
									<td style="border-left: 1px solid;"><div style="margin-left:10px;">${node.unit}</div></td>
									<td style="border-left: 1px solid; border-right: 1px solid;"><div style="margin-left:10px;"><c:if test="${!empty node.lowNormal}">
										${node.lowNormal}
									</c:if> <c:if
											test="${!empty node.lowNormal || !empty node.highNormal}">
										-
									</c:if> <c:if test="${!empty node.highNormal}">
										${node.highNormal}
									</c:if></div>
									</td>
								</tr>
							</c:if>								
						</c:forEach>
						<tr>
							<td style="border-bottom: 1px solid; border-left: 1px solid;"><br/></td>
							<td style="border-bottom: 1px solid; border-left: 1px solid;"></td>
							<td style="border-bottom: 1px solid; border-left: 1px solid;"></td>
							<td style="border-bottom: 1px solid; border-left: 1px solid; border-right: 1px solid;"></td>
						</tr>
					</table>
					<br />
					<br />
					<br />
					<div style="text-align: right; padding-right: 150px;">Signature</div>
					<br />
					<br />
					<br />
				</div>
				
				<!-- for printing -->
				<div id="printingstuff" name="printingstuff" style="display:none;">
					<div style="margin-top:60px; font-family:Verdana,'Lucida Grande','Trebuchet MS',Arial,Sans-Serif; font-style:normal; font-size:12px;">
					<table cellspacing="5" width="90%">
						<tr>
							<td width="75px" style="text-align:right;">ID. No:</td>
							<td width="200px"><b>${model.patient.patientIdentifier.identifier}</b></td>
							<td width="100px" style="text-align:right;">Age:</td>
							<td width="100px"><b>${model.patient.age}</b></td>
							<td width="75px" style="text-align:right;">Gender:</td>
							<td width="100px"><b><c:choose>
									<c:when test="${model.patient.gender eq 'M'}">Male</c:when>
									<c:otherwise>Female</c:otherwise>
								</c:choose>
								</b>
							</td>
						</tr>
						<tr>
							<td style="text-align:right;">Name:</td>
							<td><b>${model.patient.personName.givenName}
								${model.patient.personName.middleName}
								${model.patient.personName.familyName}
								</b>
							</td>
							<td style="text-align:right;">Order date:</td>
							<td><b>${param.orderDate}</b></td>
							<td></td>
							<td></td>
						</tr>
					</table>
					</div>
					<br />
					<div style="margin-top:30px; font-family:Verdana,'Lucida Grande','Trebuchet MS',Arial,Sans-Serif; font-style:normal; font-size:12px;">
						<table style="width: 90%" cellspacing="0">
						<tr>
							<td width="46%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; text-align:center;"><b>Test</b></td>
							<td width="27%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; text-align:center;"><b>Result</b></td>
							<td width="10%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; text-align:center;"><b>Unit</b></td>
							<td width="17%" style="border-top: 1px solid; border-bottom: 1px solid; border-left: 1px solid; border-right: 1px solid; text-align:center;"><b>Reference Range</b></td>
						</tr>
						<c:forEach items="${model.nodes}" var="node">
							<c:if test="${not (node.level eq 1 and empty node.childNodes)}">
								<tr>
									<td style="border-left: 1px solid;">
										<div style="margin-left:${15*node.level}px;">
											<c:choose>
												<c:when test="${node.level eq 1}">
													<br />
													<strong>${node.name}</strong>
												</c:when>
												<c:otherwise>
												${node.name}
											</c:otherwise>
											</c:choose>
										</div>
									</td>
									<td style="border-left: 1px solid;"><div style="margin-left:10px;">${node.result}</div></td>
									<td style="border-left: 1px solid;"><div style="margin-left:10px;">${node.unit}</div></td>
									<td style="border-left: 1px solid; border-right: 1px solid;"><div style="margin-left:10px;"><c:if test="${!empty node.lowNormal}">
										${node.lowNormal}
									</c:if> <c:if
											test="${!empty node.lowNormal || !empty node.highNormal}">
										-
									</c:if> <c:if test="${!empty node.highNormal}">
										${node.highNormal}
									</c:if></div>
									</td>
								</tr>
							</c:if>								
						</c:forEach>
						<tr>
							<td style="border-bottom: 1px solid; border-left: 1px solid;"><br/></td>
							<td style="border-bottom: 1px solid; border-left: 1px solid;"></td>
							<td style="border-bottom: 1px solid; border-left: 1px solid;"></td>
							<td style="border-bottom: 1px solid; border-left: 1px solid; border-right: 1px solid;"></td>
						</tr>
					</table>
					</div>
					<br />
					<br />
					<br />
					<div style="text-align: right; padding-right: 150px;">Signature</div>
					<br />
					<br />
					<br />
				</div>
				<!-- for printing -->
				<br />
				<input type="button" name="printButton" value="Print"
					onclick="printDiv()" />
					
				<script>
					function printDiv()
				    {	
				        var printer = window.open('','','width=800,height=500,scrollbars=yes,resizable=yes');
				        printer.document.open("text/html");
						var docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
						printer.document.write(docType + 
						"<html><head></head><body><div style='margin-top:50px; font-size:12px;'>" + 
							document.getElementById('printingstuff').innerHTML
							+
						"</div></body></html>");
				        printer.document.close();				        
				        printer.print();		
						printer.close();							
				    } 
				</script>
			</c:when>
			<c:otherwise>
				Can not find patient.
			</c:otherwise>
		</c:choose>
	</c:otherwise>
</c:choose>